Ruby: if statement using regexp and boolean operator [migrated]

Posted by bev on Programmers See other posts from Programmers or by bev
Published on 2012-12-07T00:01:52Z Indexed on 2012/12/07 5:20 UTC
Read the original article Hit count: 218

Filed under:

I'm learning Ruby and have failed to make a compound 'if' statement work. Here's my code (hopefully self explanatory)

commentline = Regexp.new('^;;') 
blankline = Regexp.new('^(\s*)$')

if (line !~ commentline || line !~ blankline)
  puts line
end

the variable 'line' is gotten from reading the following file:

;; alias filename backupDir

Prog_i  Prog_i.rb ./store
Prog_ii Prog_ii.rb ./store

This fails and I'm not sure why. Basically I want the comment lines and blank lines to be ignored during the processing of the lines in the file. Thanks for your help.

© Programmers or respective owner

Related posts about ruby